#!/bin/bash
#
# Checks to see if the subscription is up to date
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 19 November 2013
#
#   Copyright 2012-2013 Coastal Carolina University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#


## p_cmd_check_update_help
##
## Echoes help information for the check_update command. Returns 0.
##
function p_cmd_check_update_help() {
	cat << EOF
Usage: pulley check_update

Checks to see if the local subscription is up to date, or if an updated
version of the subscription is available from the server. Exits with a status
of 0 if the local copy of the subscription is up to date, or 100 if an
updated version of the subscription is available for download. Any other
exit status indicates an error.
EOF
	return 0
}


## p_cmd_check_update_summary
##
## Echoes summary information for the check_update command. Returns 0.
##
function p_cmd_check_update_summary() {
	echo "Checks for subscription updates"
	return 0
}


## p_cmd_check_update
##
## Implements the check_update command for Pulley. Checks to see if a
## subscription update is available, then queries each enabled agent to see
## if the agent detects available updates. Returns 0 if no updates are
## available, 100 if updates are available, and non-zero if an error occurs.
##
function p_cmd_check_update() {
	local status=0
	psub_check_update
	status=$?
	
	if [ $status -ne 100 ]; then
		check_agents
		status=$?
	fi
	return ${status}
}
